package com.amit.hibernate;



public class HibernateCustomerDAO implements CustomerDAO {

	

	@Override
	public int addCustomer(CustomerTO cto) {
		
Customer cust=new Customer(cto.getCname(),cto.getEmail(),cto.getPhone(),cto.getCity(),cto.getStatus());

Integer it=(Integer) HibernateTemplate.saveObject(cust);

	return it.intValue();
		
	}

	@Override
	public CustomerTO getcustomerbyCid(int cid) {
		Customer cust=(Customer) HibernateTemplate.loadObject(Customer.class,cid);
		CustomerTO cto=new CustomerTO(cust.getCid(), cust.getCname(), cust.getEmail(), cust.getPhone(), cust.getCity(), cust.getStatus());
		
		return cto;
	}

	@Override
	public void deleteCustomer(int cid) {
		
		HibernateTemplate.deleteObject(Customer.class,cid);
		
	}

	@Override
	public void updateCustomer(CustomerTO c2) {
		
		Customer cust=new Customer(c2.getCid(), c2.getCname(), c2.getEmail(), c2.getPhone(),c2.getCity(), c2.getStatus());
		HibernateTemplate.updateObject(cust);
	}

}
